package com.example.admin.brainwave.utils;

import android.content.Context;


import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Tony.Fan on 2018/3/12 16:08
 */
public class OKHttpInterceptor implements Interceptor {
    private Context mContext;

    /**
     * @param context 需要传入一个界面相关的Context 因为需要处理 toast
     */
    public OKHttpInterceptor(Context context) {
        this.mContext = context;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request.Builder requestBuilder = chain.request().newBuilder();
        requestBuilder = TokenUtil.addUserTokenIfPossible(mContext, requestBuilder);
        Request newRequest = requestBuilder.build();
        return chain.proceed(newRequest);
    }

}
